<template>
  <el-row :gutter="40" class="panel-group">
    <el-col
      :xs="24"
      :sm="24"
      :lg="24"
      class="card-panel-col-title"
      style="padding: 0;"
    >
      <div class="sigma-content">
        <div class="sigma-middle-line">
          <div class="sigma-line-text">
            <div class="sigma-title">渠道监测</div>
            <div style="float:right;">
              <el-button
                :type="channelType == '' ? 'primary' : ''"
                size="small"
                style="width:80px;border-radius:2px;"
                @click="channelType = ''"
                >UV</el-button
              >
              <el-button
                :type="channelType == 'JOINT' ? 'primary' : ''"
                size="small"
                style="width:80px;border-radius:2px;margin-left: -5px;"
                @click="channelType = 'JOINT'"
                >联登</el-button
              >
              <el-button
                :type="channelType == 'FORM' ? 'primary' : ''"
                size="small"
                style="width:80px;border-radius:2px;margin-left: -5px;"
                @click="channelType = 'FORM'"
                >导单</el-button
              >
              <el-button
                :type="channelType == 'AUTH_API' ? 'primary' : ''"
                size="small"
                style="width:80px;border-radius:2px;margin-left: -5px;"
                @click="channelType = 'AUTH_API'"
                >API进件</el-button
              >
            </div>
          </div>
        </div>
      </div>
    </el-col>
    <el-col
      :xs="24"
      :sm="24"
      :lg="24"
      class="card-panel-col"
      style="padding: 16px;"
    >
      <el-table
        :data="tableData"
        v-bind="loading"
        border
        style="width: 100%"
        :header-cell-style="{
          background: '#E4EFFF',
          color: '#666666'
        }"
      >
        <el-table-column label="总UV" align="center">
          <template slot-scope="{ row }">
            <span style="color: #376DF7;">{{ row.uvNum }}</span>
          </template></el-table-column
        >
        <el-table-column prop="regNum" label="注册量" align="center">
        </el-table-column>
        <el-table-column prop="regPercent" label="注册率" align="center">
        </el-table-column>
        <el-table-column prop="agencySucNum" label="完件量" align="center">
        </el-table-column>
        <el-table-column prop="agencySucPercent" label="完件率" align="center">
        </el-table-column>
        <el-table-column
          prop="agencyNum"
          label="机构进件量"
          align="center"
          min-width="100px"
        >
        </el-table-column>
        <el-table-column
          prop="apiSuccNum"
          label="API成功量"
          align="center"
          min-width="90px"
        >
        </el-table-column
        ><el-table-column prop="pushRate" label="推送率" align="center">
        </el-table-column>
        <el-table-column prop="outLay" label="渠道支出" align="center">
        </el-table-column>
        <el-table-column prop="income" label="营收" align="center">
        </el-table-column>
        <el-table-column prop="roi" label="ROI" align="center">
        </el-table-column>
      </el-table>
    </el-col>
  </el-row>
</template>

<script>
import { channelDetect } from '@/api/home';
export default {
  props: {
    chartData: {
      type: Array
    }
  },
  data() {
    return {
      listQuery: {
        channelType: '',
        startTime: this.chartData.startTime,
        endTime: this.chartData.endTime
      },
      channelType: '',
      times: [],
      ROI: [],
      tableData: [],
      loading: true
    };
  },
  created() {
    this.getRoi();
  },
  watch: {
    channelType: {
      deep: true,
      handler(val) {
        this.listQuery.channelType = this.channelType;
        this.getRoi();
      }
    },
    chartData: {
      deep: true,
      handler(val) {
        this.listQuery.startTime = val.startTime;
        this.listQuery.endTime = val.endTime;
        this.getRoi();
      }
    }
  },
  methods: {
    async getRoi() {
      this.loading = true;
      console.log(this.loading);
      const res = await channelDetect(this.listQuery);
      if (res.data.code === 200) {
        this.tableData = res.data.data;
        // this.loading = false;
      } else {
        // this.loading = false;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.panel-group {
  margin: 16px 0 !important;
  .card-panel-col {
    background: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 2px;
  }
  .card-panel {
    font-size: 12px;
    position: relative;
    overflow: hidden;
    background: #ffffff;
    .icon-people {
      color: #40c9c6;
    }
    .icon-message {
      color: #36a3f7;
    }
    .icon-shopping {
      color: #34bfa3;
    }
    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }
    .card-panel-text {
      line-height: 14px;
      color: #354768;
      font-size: 14px;
      margin-bottom: 12px;
    }
    .card-panel-num {
      font-size: 20px;
    }
    .straight {
      color: #376df7;
    }
    .burden {
      color: #67c23a;
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }
  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;
    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
.vip-p {
  text-align: left;
  color: #354768;
  font-size: 16px;
  padding: 5px 0;
}
.vip-title {
  color: #8f97a7;
}
.vip-title::before {
  content: '';
  display: inline-block;
  vertical-align: 3px;
  margin-right: 10px;
  background: #167bff;
  width: 6px;
  height: 6px;
  border-radius: 3px;
}
.sigma-content {
  background-color: #ffffff;
}
.sigma-title {
  position: absolute;
  top: 20px;
  left: 16px;
  width: 100px;
  font-size: 16px;
  border-left: 3px solid #376df7;
  padding: 0 4px;
  margin: 2px 0;
  line-height: 10px;
}
.sigma-line-text {
  width: 100%;
  display: inline-block;
  position: relative;
  padding: 16px 16px 0 16px;
  font-size: 14px;
  font-weight: 500;
}
</style>
